package engine.display.Story.ActionItem
{
	import com.greensock.TweenLite;
	
	import engine.display.Story.ActionControl.TimerTextField;
	import engine.display.Story.StoryMoveEvent.StoryEvent;
	import engine.display.Story.StoryVo;
	
	import flash.display.Sprite;
	import flash.text.TextFormat;

	public class EndBlackTalkInfoUI extends BaseAction
	{
		private static var _self	:EndBlackTalkInfoUI;
		private var backBG			:Sprite
		private var textFormat		:TextFormat;
		private var infoText		:TimerTextField;
//		private var timer			:Timer;
		private var timerNum		:int	=	2000;
		private var alphaMax		:int	=	100;
		
		public function EndBlackTalkInfoUI()
		{
			init();
		}
		public static function getInstance():EndBlackTalkInfoUI
		{
			if(_self == null)
			{
				_self	=	new EndBlackTalkInfoUI();
			}
			return _self;
		}
		
		override public function showInfo(val:StoryVo):void
		{
			alphaMax	=	100
			this.alpha	=	1
			infoText.text	=	val.TalkInfo;
		}
		
		private function init():void
		{
			backBG			=	new Sprite();
			backBG.graphics.beginFill(0x000000);
			backBG.graphics.drawRect(0, 0, 1280 ,768);
			backBG.graphics.endFill();
			
			textFormat					=	new TextFormat();
			textFormat.bold				=	true;
			textFormat.size				=	24;
			textFormat.color			=	0xFFFF00;
			
			infoText					=	new TimerTextField();
			infoText.selectable			=	false;
			infoText.width				=	600;
			infoText.height				=	200;
			infoText.x					=	200;
			infoText.y					=	200;
			infoText.timerlenght		=	100;
			infoText.wordWrap			=	true
			infoText.defaultTextFormat	=	textFormat;
			infoText.setTextFormat(textFormat);
			
			this.addChild(backBG);
			this.addChild(infoText);
			
			infoText.addEventListener(StoryEvent.TEXT_OVER, talkOverHandle)
		}
		/**
		 * 文字动画完成了
		 * @param	e
		 */
		private function talkOverHandle(e:StoryEvent):void 
		{
			dispatchEvent(new StoryEvent(StoryEvent.SHOW_SCENE));
			
			alpha = 1;
			TweenLite.to( this, 1, {alpha:0, onComplete:actionOver});
		}
//		/**
//		 * 计时控件 
//		 * @param e
//		 * 
//		 */		
//		private function timerHandle(e:TimerEvent):void 
//		{
//			alphaMax-=10;
//			this.alpha 	=	alphaMax / 100;
//			if (alphaMax <= 0) 
//			{
//				this.alpha	=	0;
//				timer.stop();
//				actionOver();
//			}
//		}
		/**
		 * 场景尺寸改变
		 */
		public function changeLocation(stageWidth:int,stageHeight:int):void
		{
			backBG.width	=	stageWidth * 3;
			backBG.height	=	stageHeight * 3;
			backBG.x		=	-stageWidth;
			backBG.y		=	-stageHeight;
			infoText.x		=	(stageWidth - 600) * .5;
		}
	}
}